<?php

namespace app\interfaces\controller;

use app\infrastructure\base\BaseApi;
use app\interfaces\service\OrderService;

class OrderController extends BaseApi
{
    /**
     * 创建订单
     * @apiurl /interfaces/order/create
     */
    public function create()
    {
        OrderService::createOrder($this->data['user_id'], $this->data['amount']);
        return $this->jsonSuccess();
    }

    /**
     * 查看订单详情
     * @apiurl /interfaces/order/getById
     */
    public function getById()
    {
        $this->jsonResult(
            OrderService::getOrderById($this->data['id'])
        );
    }

    /**
     * 获取订单信息
     * @apiurl /interfaces/order/getInfo
     */
    public function getInfo()
    {
        // $this->data 当前请求参数，原理也比较简单，对请求参数进行了过滤如后的数据
        $this->data['user_id'] = 1; // 默认示例已经通过，账号自动验证

        $this->jsonResult(OrderService::orderInfo($this->data));
    }
}